package designPattern;

import java.lang.reflect.Proxy;

public class LamdaJdkProxy {
    //test
    public static void main(String[] args) {
        Project2 proxyProject = new JdkProxyHandler2<Project2>(new RealProject2()).getProxyInstance();
        proxyProject.development();
        proxyProject.test();
    }
}

//interface
interface Project2 {
    void development();

    void test();
}

//real implements
class RealProject2 implements Project2 {
    @Override
    public void development() {
        System.out.println("development project with Java");
    }

    @Override
    public void test() {
        System.out.println("finish development , let us to test");
    }
}

//dynamic proxy implements
class JdkProxyHandler2<C> {
    private C proxyClass;

    public JdkProxyHandler2(C proxyClass) {
        this.proxyClass = proxyClass;
    }

    public C getProxyInstance() {
        return (C) Proxy.newProxyInstance(proxyClass.getClass().getClassLoader(), proxyClass.getClass().getInterfaces(), (proxy, method, args) ->
        {
            System.out.println("before doing");
            Object object = method.invoke(proxyClass, args);
            System.out.println("after doing");
            return object;
        });
    }

}